package cn.edu.ren.controller;

import cn.edu.ren.entity.Item;
import cn.edu.ren.service.ItemService01;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.data.domain.Pageable;
import java.util.List;

/**
 * @PackageName: cn.edu.ren.controller
 * @ClassName: ItemController
 * @Description:
 * @author: RZS
 * @date: 2021/7/12  16:44
 */
@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService01 itemService01;

    // 根据标题查询(不含分页)
    @GetMapping("/title")
    List<Item> findByTitle(String title){
        return itemService01.findByTitle(title);
    }

    // 根据标题查询(含分页)
    @GetMapping("/title_page")
    List<Item> findByTitlePage(String title){
        Pageable pageable = PageRequest.of(0, 3);
        return itemService01.findByTitle(title, pageable);
    }

    // 根据匹配和分类进行查询
    @GetMapping("/brand_category")
    List<Item> findByBrandAndCategory(String brand, String category){
        return itemService01.findByBrandAndCategory(brand, category);
    }

    // 查询指定品牌名的数据或者小于指定价格的数据
    @GetMapping("/brand_price")
    List<Item> findByBrandOrPriceLessThan(String brand, Double price){
        return itemService01.findByBrandOrPriceLessThan(brand, price);
    }

    // 获取分类不是指定分类的数据(含分页)
    @GetMapping("/category_not")
    List<Item> findByCategoryNot(String category){
        Pageable pageable = PageRequest.of(0, 3);
        return itemService01.findByCategoryNot(category, pageable);
    }

    // 查询指定价格范围内的数据（含分页）
    @GetMapping("/price_bet")
    List<Item> findByPriceBetween(Double d1, Double d2){
        return itemService01.findByPriceBetween(d1, d2);
    }
}
